package com.StarStudio.Service.Impl;

import cn.hutool.core.util.IdUtil;
import com.StarStudio.DAO.BeansActionDAO;
import com.StarStudio.DAO.UserInfoDAO;
import com.ruoyi.common.core.Entity.BeansAction;
import com.StarStudio.Service.BeansActionService;
import com.ruoyi.common.core.Entity.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class BeansActionServiceImpl implements BeansActionService {

    @Autowired
    private BeansActionDAO beansActionDAO;

    @Autowired
    UserInfoDAO userInfoDAO;

    @Override
    public List<BeansAction> findBeansActionList(BeansAction beansAction) {
        List<BeansAction> beansActionList = beansActionDAO.findBeansActionList(beansAction);
        if (beansActionList != null && beansActionList.size() > 0){
            for (BeansAction action : beansActionList) {
                Map<String,Object> param = new HashMap<>();
                UserInfo userInfo = userInfoDAO.findByUser_id(action.getBeans_action_user_id());
                param.put("userName",userInfo.getReal_name());
                action.setParams(param);
            }
        }
        return beansActionList;
    }

    @Override
    public BeansAction findByBeansAction_id(long id) {
        return beansActionDAO.findByBeansAction_id(id);
    }

    @Override
    public List<BeansAction> findByBeansAction_user_id(long id) {
        return beansActionDAO.findByBeansAction_user_id(id);
    }

    @Override
    public void deleteBeansActionById(long id) {
        beansActionDAO.deleteBeansActionById(id);
    }

    @Override
    public void addBeansAction(BeansAction beansAction) {
        beansAction.setBeans_action_id(IdUtil.getSnowflakeNextId()); //使用雪花ID
        beansActionDAO.addBeansAction(beansAction);
    }

    @Override
    public void updateBeansAction(BeansAction beansAction) {
        beansActionDAO.updateBeansAction(beansAction);
    }

    @Override
    public long findAllRecordNumber() {
        return beansActionDAO.findAllRecordNumber();
    }
}
